/**
 * @module Promiseify WX
 */
// const Request = require('./request.js') 


const noPromiseMaths = new Set([
    'stopRecord',
    'pauseVoice',
    'stopVoice',
    'pauseBackgroundAudio',
    'stopBackgroundAudio',
    'showNavigationBarLoading',
    'hideNavigationBarLoading',
    'createAnimation',
    'createContext',
    'hideKeyboard',
    'stopPullDownRefresh',
    'Http'
])


const wxmp = {

};


Object.keys(wx).forEach(key =>{

    
    if(!wx.hasOwnProperty(key)){ return }
    const noPromise = noPromiseMaths.has(key) || (key.indexOf('on') == 0) || /w+Sync$/.test(key) || typeof wx[key] !== 'function';

    if(!noPromise){

       wxmp[key] = function( obj={}, ...args){

            return new Promise((resolve,  reject) =>{
                obj.success = resolve;
                obj.fail = reject;                 
                wx[key](obj, ...args)
            })
            
        }           
        
        return
    }

    if(typeof wx[key] === 'function'){
        wxmp[key] = wx[key]
        return
    }

    wxmp[key] = wx[key]
    
})


module.exports = wxmp;